package language.advanced.reflect.dynamicProxy.cglibTest;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class MyAopWithCGlib implements MethodInterceptor {
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        Annotation[] annotations = method.getDeclaredAnnotations();
        boolean isCglib = false;
        for(Annotation annotation: annotations){
            if (annotation.annotationType().getName().equals("com.example.demo.aop.AOPtest")){
                isCglib = true;
            }
        }
        if(isCglib) {
            System.out.println("嘿，你在干嘛？");
            methodProxy.invokeSuper(o, objects);
            System.out.println("是的，你说的没错。");
        }
        return null;
    }
}